package com.algorithm.string_and_array;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

@Slf4j
public class DoublePointerSolutionLC06 {

    public int minSubArrayLen(int target, int[] nums) {
        int len = 0;
        int result = 0;
        int i = 0;
        while (i < nums.length) {
            int sum = 0;
            for (int k = i; k < nums.length; k++) {
                sum = sum + nums[k];
                if (sum >= target) {
                    len = k - i+1;
                    break;
                }
            }
            if (result == 0) {
                result = len;
            } else {
                result = result > len ? len : result;
            }
            i++;
        }
        return result;
    }

    @Test
    public void test(){
        int target = 7;
        int [] nums = {2,3,1,2,4,3};
        int i = minSubArrayLen(target, nums);
        log.info("result is {}",i);
    }
}
